package com.csdj.tangchujun.controller;

import com.csdj.tangchujun.entity.TUser;
import com.csdj.tangchujun.entity.TUserExample;
import com.csdj.tangchujun.service.ITUserService;
import com.csdj.tangchujun.service.RedisService;
import com.csdj.tangchujun.util.Md5Utils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;

@Controller
public class LoginController {
    @Resource
    private ITUserService tUserService;
    @Resource
    private RedisService redisService;
    @GetMapping("login")
    public String login(){
        return "/login";
    }
    @PostMapping("loginTo")
    public String loginTo(String userCode, String userPassword, Model model){
        String pwd= Md5Utils.md5(userPassword);
        TUserExample tUserExample = new TUserExample();
        tUserExample.createCriteria().andUserCodeEqualTo(userCode).andUserPasswordEqualTo(pwd);
        TUser tUser =tUserService.selectByExample(tUserExample).get(0);
        if(tUser!=null){
            model.addAttribute("tUser",tUser);
            return "/index";
        }
        return null;
    }
}
